<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>吸顶效果</title>
    </head>

    <style>
        body{
            height: 2000px;
            background-image: linear-gradient(-180deg, #15f09d 0%, #25A0FF 50%, #fca72b 100%);
        }

        #wrap {
            background-color: rgba(0,0,0,0.2);
            width: 100%;
            height: 100px;
            margin-top: 100px;
            position: sticky;
        }

        /* #wrap[data-fixed="fixed"]{
            position: fixed;
            top:0;
            left: 0;
            margin: 0;
        } */
    </style>
    <body>
        <div id="wrap"></div>
    </body>

    <script>
            // var obj = document.getElementById("wrap");
            // var ot = obj.offsetTop;
            // console.log("offset:" + ot);
            // document.onscroll = function () {
            //     var st = document.body.scrollTop || document.documentElement.scrollTop;
            //     console.log("document offset:" + st);
            //     obj.setAttribute("data-fixed",st >= ot?"fixed":"")}
    </script>    
</html>